package com.lanqiao.service.impl;

import com.lanqiao.dao.BookDao;
import com.lanqiao.dao.BookPicDao;
import com.lanqiao.dao.impl.BookDaoImpl;
import com.lanqiao.dao.impl.BookPicDaoImpl;
import com.lanqiao.entity.BookInfo;
import com.lanqiao.entity.BookPicInfo;
import com.lanqiao.service.BookService;

import java.util.List;

public class BookServiceImpl implements BookService {
    private BookDao bookDao = new BookDaoImpl();
    private BookPicDao bookPicDao = new BookPicDaoImpl();
    @Override
    public boolean addBook(BookInfo bookInfo, List<String> pic_names) {
        // 返回插入图的自增长id
        int bookId = bookDao.insertBook(bookInfo);
        if(pic_names.size() > 0){
            //循环插入小图
            for(String pic_name : pic_names){
                BookPicInfo bookPicInfo = new BookPicInfo();
                bookPicInfo.setBook_id(bookId);
                bookPicInfo.setPic_name(pic_name);
                //调用插入小图的功能 返回影响sql的行数
                int row = bookPicDao.insertBookPic(bookPicInfo);
            }
        }
        return bookId > 0;
    }

    @Override
    public List<BookInfo> selectBook() {
        return null;
    }
}
